# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgbase=python-python-magic
pkgname=('python2-python-magic' 'python-python-magic')
_pkgname=python-magic
pkgver=0.4.27
_pyver=3.13
pkgrel=1
pkgdesc='File type identification using libmagic.'
arch=('any')
url='https://pypi.org/project/python-magic/#files'
license=('MIT')
makedepends=('python2-setuptools' 'python-setuptools' 'python2-pip' 'python-pip'
             'python2-wheel' 'python-wheel')
source=("https://files.pythonhosted.org/packages/source/${_pkgname::1}/$_pkgname/$_pkgname-$pkgver.tar.gz")
sha512sums=('2aea0a87f010b4624bdf6de18e4effd23282265089aea3d666abd8d74742d7f89c7abd1146e17a405653278d777663b2cb59afd812d6c8885ea034c318088b1f')

prepare() {
  cp -a "$_pkgname-$pkgver"{,-2}
}

build() {
  cd "$_pkgname-$pkgver-2"

  python2 setup.py build

  cd "$srcdir/$_pkgname-$pkgver"

  python setup.py build
}

package_python2-python-magic() {
  depends=('python2' 'python2-libmagic')

  cd "$_pkgname-$pkgver"

  python2 setup.py install --root="$pkgdir" --prefix=/usr -O1 --skip-build

  mkdir -p "$pkgdir/usr/lib/python2.7/site-packages/"{python-magic,python_magic}
  cp -af magic.py* "$pkgdir/usr/lib/python2.7/site-packages/python_magic/"
  find $pkgdir -type d -name '__pycache__' -exec rm -rf {} +
  rm -f "$pkgdir/usr/lib/python2.7/site-packages/magic."{py,pyc,pyo}
}

package_python-python-magic() {
  depends=('python' 'python-libmagic')

  cd "$_pkgname-$pkgver"

  python setup.py install --root="$pkgdir" --prefix=/usr -O1 --skip-build

  mkdir -p "$pkgdir/usr/lib/python$_pyver/site-packages/"{python-magic,python_magic}
  cp -af magic.py* "$pkgdir/usr/lib/python$_pyver/site-packages/python_magic/"
  find $pkgdir -type d -name '__pycache__' -exec rm -rf {} +
  rm -f "$pkgdir/usr/lib/python$_pyver/site-packages/magic.py"
}

